﻿cmake_minimum_required(VERSION 3.5)

set(CMAKE_CXX_STANDARD 17)
project(guild-client)

IF (MSVC)
ELSE()
  SET(CMAKE_CXX_FLAGS "-m64 -g -O0 -std=c++17 -Wall -Wno-unused-variable -fnon-call-exceptions")
  set(CMAKE_CXX_COMPILER "g++")
ENDIF()

include_directories(
    ${PROJECT_SOURCE_DIR}/../../../../..
    ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/include
    ${PROJECT_SOURCE_DIR}/../../../../src/include/root
    ${PROJECT_SOURCE_DIR}/../../../../src/include/guildservicebasic
    ${PROJECT_SOURCE_DIR}/../../../../src/include/guildservicequery
    ${PROJECT_SOURCE_DIR}/../../../../src/include/guildservicewelfare
    ${PROJECT_SOURCE_DIR}/../../../../src/include/guildserviceauth
    ${PROJECT_SOURCE_DIR}/../../../../src/include/guildservicetimer
    ${PROJECT_SOURCE_DIR}/../../../../src/include/guildservicebuilding
    ${PROJECT_SOURCE_DIR}/../../../../src/include
    ${PROJECT_SOURCE_DIR}/../../../../usr/impl/guildservicewelfare/GuildClientWelfare
    ${PROJECT_SOURCE_DIR}/../../../../thirdparty/include
    ${PROJECT_SOURCE_DIR}/../../include/guild
)

aux_source_directory(. SRC_FILES)

if(WIN32)
    message("WIN32")
else()
    message("LINUX")
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicebasic/GuildServiceBasic)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebasic)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicequery/GuildServiceQuery)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/guildservicequery)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicewelfare/GuildServiceWelfare)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/guildservicewelfare)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicewelfare/GuildServiceTimer)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetimer)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildserviceauth/GuildServiceAuth)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceauth)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildClientWelfare)
    link_directories(${PROJECT_SOURCE_DIR}/../../../../../lib) #libservice_box.a
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/root) #librpc.a
    link_directories(${PROJECT_SOURCE_DIR}/../../../../thirdparty/lib/linux) #libprotobuf.a
    link_directories(/usr/local/lib) #libhiredis.a libz.a libcurl.a libhashtable.a libzookeeper.a
endif()

add_executable (
    guild_client
    ${SRC_FILES}    
)

# if(WIN32)
if (MSVC)
	message("WIN32")
foreach(var
  CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(${var} MATCHES "/MD")
  string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
endif()
endforeach()
    set_target_properties(guild_client PROPERTIES COMPILE_FLAGS "/EHsc /W3")

SET_TARGET_PROPERTIES(guild_client PROPERTIES LINK_FLAGS_DEBUG "
    ${PROJECT_SOURCE_DIR}/../../../../lib/root/Debug/librpc.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebasic/Debug/libguildservicebasic.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicequery/Debug/libguildservicequery.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicewelfare/Debug/libguildservicewelfare.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceauth/Debug/libguildserviceauth.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetimer/Debug/libguildservicetimer.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebuilding/Debug/libguildservicebuilding.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicebasic/GuildServiceBasic/Debug/libGuildServiceBasic_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicequery/GuildServiceQuery/Debug/libGuildServiceQuery_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicewelfare/GuildServiceWelfare/Debug/libGuildServiceWelfare_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildserviceauth/GuildServiceAuth/Debug/libGuildServiceAuth_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicebuilding/GuildServiceBuilding/Debug/libGuildServiceBuilding_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildClientWelfare/Debug/libGuildClientWelfare_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildClientWelfare/Debug/libGuildClientWelfare.a
")
SET_TARGET_PROPERTIES(guild_client PROPERTIES LINK_FLAGS_RELEASE "
    ${PROJECT_SOURCE_DIR}/../../../../lib/root/Release/librpc.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebasic/Release/libguildservicebasic.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicequery/Release/libguildservicequery.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicewelfare/Release/libguildservicewelfare.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceauth/Release/libguildserviceauth.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetimer/Release/libguildservicetimer.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebuilding/Release/libguildservicebuilding.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicebasic/GuildServiceBasic/Release/libGuildServiceBasic_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicequery/GuildServiceQuery/Release/libGuildServiceQuery_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicewelfare/GuildServiceWelfare/Release/libGuildServiceWelfare_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildserviceauth/GuildServiceAuth/Release/libGuildServiceAuth_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicetimer/GuildServiceTimer/Release/libGuildServiceTimer_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicebuilding/GuildServiceBuilding/Release/libGuildServiceBuilding_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildClientWelfare/Release/libGuildClientWelfare_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildClientWelfare/Release/libGuildClientWelfare.a
")



    target_link_libraries(guild_client
        debug ${PROJECT_SOURCE_DIR}/../../../../../../win-proj/x64/Debug/service-box.lib optimized ${PROJECT_SOURCE_DIR}/../../../../../../win-proj/x64/Release/service-box.lib
        ${PROJECT_SOURCE_DIR}/../../../../thirdparty/lib/windows/debug/libprotobufd.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/zookeeper.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/hashtable.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/hiredis.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/Win32_Interop.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/libcurl.a

        wldap32.lib
        ws2_32.lib
        psapi.lib
    )
else()
    message("LINUX")
    target_link_libraries(guild_client
        libservice_box.a
        # librpc.a
        libprotobuf.a
        libzookeeper.a
        libhashtable.a
        libhiredis.a
        libcurl.a
        libz.a
        -Wl,--whole-archive
        ${PROJECT_SOURCE_DIR}/../../../../lib/root/librpc.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebasic/libguildservicebasic.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicequery/libguildservicequery.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicewelfare/libguildservicewelfare.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceauth/libguildserviceauth.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetimer/libguildservicetimer.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebuilding/libguildservicebuilding.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicebasic/GuildServiceBasic/libGuildServiceBasic_proxy.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicequery/GuildServiceQuery/libGuildServiceQuery_proxy.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicewelfare/GuildServiceWelfare/libGuildServiceWelfare_proxy.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildserviceauth/GuildServiceAuth/libGuildServiceAuth_proxy.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicetimer/GuildServiceTimer/libGuildServiceTimer_proxy.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicebuilding/GuildServiceBuilding/libGuildServiceBuilding_proxy.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildClientWelfare/libGuildClientWelfare_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildClientWelfare/libGuildClientWelfare.a

        -Wl,--no-whole-archive
        -lpthread
        -ldl
    )
endif()
